<template>
    <rx-dialog @handOk="handOk" @cancel="cancel">
        <div class="formBodefLayout">
            <div style="padding: 6px 0;">
                <a-form layout="inline">
                    <a-row :gutter="24">
                        <a-col :span="8">
                            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 19 }" :label="i18n('form.name','名称')">
                                <a-input :placeholder="i18n('form.name','名称','input')"
                                         v-model.trim="queryParam.Q_NAME__S_LK"/>
                            </a-form-item>
                        </a-col>
                        <a-col :span="8">
                            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 19 }" :label="i18n('form.alias','别名')">
                                <a-input :placeholder="i18n('form.alias','别名','input')"
                                         v-model.trim="queryParam.Q_ALIAS__S_LK"/>
                            </a-form-item>
                        </a-col>

                        <a-col :span="8">
                              <span class="table-page-search-submitButtons">
                                <a-button type="primary" @click="$refs.table.loadData()"
                                          icon="search">{{ $ti18('rxList.searchBtn', '查询') }}</a-button>
                                <a-button style="margin-left: 4px" @click="resetSearch">{{ $ti18('rxList.resetBtn', '重置') }}</a-button>

                              </span>
                        </a-col>
                    </a-row>
                </a-form>
            </div>
            <div class="formBodefLayout-content">
                <div class="formBodefLayout-le">
                    <rx-category-tree ref="categoryTree" cat-key="FORM" :isGrant="true" :async="true"
                                      @select="handSelect" :isAdmin="isAdmin">
                    </rx-category-tree>
                </div>
                <div class="formBodefLayout-grid">
                    <rx-grid
                        ref="table"
                        bordered
                        :allowRowSelect="true"
                        :multiSelect="multiSelect"
                        :columns="columns"
                        :defaultPageSize="10"
                        url="/api-form/form/core/formPc/query"
                        :queryParam="queryParam"
                        data-field="result.data"
                        :pageSizeOptions="['10','30','40']"
                        id-field="id"
                        type="radio"
                        @selectChange="onSelectChange"
                        selectedRowKeys="selectedRowKeys"
                    >
          <span slot="deployed" slot-scope="{text,record}">
            <a-tag :color="statusMap[text].color">
              <span>{{ statusMap[text].text }}</span>
            </a-tag>
          </span>
                        <span slot="isShare" slot-scope="{ text, record }">
                        {{ record.createBy != "SHARE" ? $ti18('rxList.no', '否') : $ti18('rxList.yes', '是') }}
                  </span>
                        <span slot="shareAppName" slot-scope="{text,record}" :title="shareAppNameTitle(record)">
                          {{ record.createBy == "SHARE" ? $i18(record.updateBy, '应用名称') : curApp.appName }}
                        </span>
                    </rx-grid>
                </div>
            </div>
        </div>
    </rx-dialog>
</template>

<script>
import FormPcApi from '@/api/form/core/formPc'
import {BaseList, RxLayout, Util} from "@lowcode/jpaas-common-lib"

export default {
    name: 'FormPcList',
    mixins: [BaseList],
    components: {
        RxLayout
    },
    props: {
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
        multiSelect: {
            type: Boolean,
            default: true
        },
        isAdmin: {
            type: Boolean,
            default: true
        },
    },
    data() {
        return {
            columns: [
                {
                    title: '#',
                    scopedSlots: {customRender: 'serial'},
                    dataIndex: 'serial',
                    type: 'indexColumn',
                    width: 50
                },
                {title: this.i18n('form.name', '名称'), dataIndex: 'name', width: 150},
                {title: this.i18n('form.alias', '别名'), dataIndex: 'alias', width: 100},
                {
                    title: this.i18n('form.deployed', '发布状态'),
                    dataIndex: 'deployed',
                    width: 150,
                    scopedSlots: {customRender: 'deployed'}
                },
                {title: this.i18n('form.version', '版本号'), dataIndex: 'version', width: 100},
                {
                    title: this.$ti18('rxList.share', '共享'),
                    dataIndex: 'isShare',
                    width: 80,
                    scopedSlots: {customRender: 'isShare'}
                },
                {
                    title: this.$ti18('rxList.shareAppName', '所属应用'),
                    dataIndex: 'shareAppName',
                    width: 80,
                    scopedSlots: {customRender: 'shareAppName'}
                }
            ],
            statusMap: {
                1: {color: 'green', text: this.i18n("form.publish", "发布")},
                0: {color: 'red', text: this.i18n("form.NotPublish", "未发布")},
            },
            appId: "",
        }

    },
    created() {
        //只查询发布状态
        this.queryParam.Q_deployed__I_EQ = 1;
        this.needFilterAppId();
        let appId = this.curApp.appId;
        if (appId) {
            this.appId = appId;
            //用来判断是否显示共享数据
            this.queryParam.SHARE = true;
        }
    },
    mounted() {
        if (!this.appId) {
            //删除共享数据列
            this.$refs.table.initColumns(this.columns.splice(5, 1));
        }
    },
    methods: {
        shareAppNameTitle(record){
            return  record.createBy == "SHARE" ? this.$i18(record.updateBy, '应用名称') : this.curApp.appName
        },
        i18n(name, text, key) {
            return this.$ti18(name, text, "formPc", key);
        },
        getListByParams(parameter) {
            return FormPcApi.query(parameter)
        },
        getForm() {
            var row = this.selectedRows[0];
            return row;
        },
        cancel() {
            Util.closeWindow(this, "cancel");
        },
        handOk(e) {
            var rows = this.selectedRows;
            if (rows.length == 0) {
                e.loading = false;
                this.$message.warning(this.$ti18("rxMsa.masWarn.selectOneRecord", "请选择一行记录!"));
                return;
            }
            Util.closeWindow(this, "ok");
        },
        resetSearch() {
            this.queryParam = {};
            this.queryParam.Q_deployed__I_EQ = 1;
            if (this.appId) {
                this.queryParam.Q_APP_ID__S_EQ = this.appId;
                //用来判断是否显示共享数据
                this.queryParam.SHARE = true;
            }
            this.$nextTick(() => {
                this.$refs.table.loadData();
            })
        },
        handSelect(selKeys, e) {
            if (selKeys.length == 0) {
                delete this.queryParam.Q_CATEGORY_ID__S_EQ;
            } else {
                var treeId = selKeys[0];
                if (treeId == '0') return;
                this.queryParam.Q_CATEGORY_ID__S_EQ = treeId;
            }
            this.loadData()
        }

    }
}
</script>
<style scoped>
.formBodefLayout .formBodefLayout-content{
    overflow: hidden;
}
.formBodefLayout .formBodefLayout-le{
    overflow: auto;
}
.formBodefLayout .table-page-search-submitButtons {
    margin-bottom: 0;
}
</style>

